﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using SoftwareConsulting.BI11.Studio.InternalServices.Properties;

[assembly:CLSCompliant(true)]
namespace SoftwareConsulting.BI11.Studio.InternalServices
{
    /// <summary>
    /// Генерация ассерта
    /// </summary>
    public static class Assert
    {
        /// <summary>
        /// Идентификатор ассерта
        /// </summary>
        /// <remarks>необходимо добавлять новый для каждого ассерта</remarks>
        public enum Id
        {
            None = 0,
            Assert00001 = 1,
            Assert00002 = 2,
            Assert00003 = 3,
            Assert00004 = 4,
            Assert00005 = 5,
            Assert00006 = 6,
            Assert00007 = 7,
            Assert00008 = 8,
            Assert00009 = 9,
            Assert00010 = 10,
            Assert00011 = 11,
            Assert00012 = 12,
            Assert00013 = 13,
            Assert00014 = 14,
            Assert00015 = 15,
            Assert00016 = 16,
            Assert00017 = 17,
            Assert00018 = 18,
            Assert00019 = 19,
            Assert00020 = 20,
            Assert00021 = 21,
            Assert00022 = 22,
            Assert00023 = 23,
            Assert00024 = 24,
            Assert00025 = 25,
            Assert00026 = 26,
            Assert00027 = 27,
            Assert00028 = 28,
            Assert00029 = 29,
            Assert00030 = 30,
            Assert00031 = 31,
            Assert00032 = 32,
            Assert00033 = 33,
            Assert00034 = 34,
            Assert00035 = 35,
            Assert00036 = 36,
            Assert00037 = 37,
            Assert00038 = 38,
            Assert00039 = 39,
            Assert00040 = 40,
            Assert00041 = 41,
            Assert00042 = 42,
            Assert00043 = 43,
            Assert00044 = 44,
            Assert00045 = 45,
            Assert00046 = 46,
            Assert00047 = 47,
            Assert00048 = 48,
            Assert00049 = 49,
            Assert00050 = 50,
            Assert00051 = 51,
            Assert00052 = 52,
            Assert00053 = 53,
            Assert00054 = 54,
            Assert00055 = 55,
            Assert00056 = 56,
            Assert00057 = 57,
            Assert00058 = 58,
            Assert00059 = 59,
            Assert00060 = 60,
            Assert00061 = 61,
            Assert00062 = 62,
            Assert00063 = 63,
            Assert00064 = 64,
            Assert00065 = 65,
            Assert00066 = 66,
            Assert00067 = 67,
            Assert00068 = 68,
            Assert00069 = 69,
            Assert00070 = 70,
            Assert00071 = 71,
            Assert00072 = 72,
            Assert00073 = 73,
            Assert00074 = 74,
            Assert00075 = 75,
            Assert00076 = 76,
            Assert00077 = 77,
            Assert00078 = 78,
            Assert00079 = 79,
            Assert00080 = 80,
            Assert00081 = 81,
            Assert00082 = 82,
            Assert00083 = 83,
            Assert00084 = 84,
            Assert00085 = 85,
            Assert00086 = 86,
            Assert00087 = 87,
            Assert00088 = 88,
            Assert00089 = 89,
            Assert00090 = 90,
            Assert00091 = 91,//free
            Assert00092 = 92,
            Assert00093 = 93,//free
            Assert00094 = 94,
            Assert00095 = 95,
            Assert00096 = 96,
            Assert00097 = 97,
            Assert00098 = 98,
            Assert00099 = 99,
            Assert00100 = 100,
            Assert00101 = 101,
            Assert00102 = 102,
            Assert00103 = 103,
            Assert00104 = 104,
            Assert00105 = 105,
            Assert00106 = 106,
            Assert00107 = 107,
            Assert00108 = 108,
            Assert00109 = 109,
            Assert00110 = 110,
            Assert00111 = 111,
            Assert00112 = 112,
            Assert00113 = 113,
            Assert00114 = 114,
            Assert00115 = 115,
            Assert00116 = 116,
            Assert00117 = 117,
            Assert00118 = 118,
            Assert00119 = 119,
            Assert00120 = 120,
            Assert00121 = 121,
            Assert00122 = 122,
            Assert00123 = 123,
            Assert00124 = 124,
            Assert00125 = 125,
            Assert00126 = 126,
            Assert00127 = 127,
            Assert00128 = 128,
            Assert00129 = 129,
            Assert00130 = 130,
            Assert00131 = 131,
            Assert00132 = 132,
            Assert00133 = 133,
            Assert00134 = 134,
            Assert00135 = 135,
            Assert00136 = 136,
            Assert00137 = 137,
            Assert00138 = 138,
            Assert00139 = 139,
            Assert00140 = 140,
            Assert00141 = 141,
            Assert00142 = 142,
            Assert00143 = 143,
            Assert00144 = 144,
            Assert00145 = 145,
            Assert00146 = 146,
            Assert00147 = 147,
            Assert00148 = 148,
            Assert00149 = 149,
            Assert00150 = 150,
            Assert00151 = 151,
            Assert00152 = 152,
            Assert00153 = 153,
            Assert00154 = 154,
            Assert00155 = 155,
            Assert00156 = 156,
            Assert00157 = 157,
            Assert00158 = 158,
            Assert00159 = 159,
            Assert00160 = 160,
            Assert00161 = 161,
            Assert00162 = 162,
            Assert00163 = 163,
            Assert00164 = 164,
            Assert00165 = 165,
            Assert00166 = 166,
            Assert00167 = 167,
            Assert00168 = 168,
            Assert00169 = 169,
            Assert00170 = 170,
            Assert00171 = 171,
            Assert00172 = 172,
            Assert00173 = 173,
            Assert00174 = 174,
            Assert00175 = 175,
            Assert00176 = 176,
            Assert00177 = 177,
            Assert00178 = 178,
            Assert00179 = 179,
            Assert00180 = 180,//free
            Assert00181 = 181,
            Assert00182 = 182,
            Assert00183 = 183,
            Assert00184 = 184,
            Assert00185 = 185,
            Assert00186 = 186,
            Assert00187 = 187,
            Assert00188 = 188,
            Assert00189 = 189,
            Assert00190 = 190,
            Assert00191 = 191,
            Assert00192 = 192,
            Assert00193 = 193,
            Assert00194 = 194,
            Assert00195 = 195,
            Assert00196 = 196,
            Assert00197 = 197,
            Assert00198 = 198,
            Assert00199 = 199,
            Assert00200 = 200,
            Assert00201 = 201,
            Assert00202 = 202,
            Assert00203 = 203,
            Assert00204 = 204,
            Assert00205 = 205,
            Assert00206 = 206,
            Assert00207 = 207,
            Assert00208 = 208,
            Assert00209 = 209,
            Assert00210 = 210,
            Assert00211 = 211,
            Assert00212 = 212,
            Assert00213 = 213,
            Assert00214 = 214,
            Assert00215 = 215,
            Assert00216 = 216,
            Assert00217 = 217,
            Assert00218 = 218,
            Assert00219 = 219,
            Assert00220 = 220,
            Assert00221 = 221,
            Assert00222 = 222,
            Assert00223 = 223,
            Assert00224 = 224,
            Assert00225 = 225,
            Assert00226 = 226,
            Assert00227 = 227,
            Assert00228 = 228,
            Assert00229 = 229,
            Assert00230 = 230,
            Assert00231 = 231,
            Assert00232 = 232,
            Assert00233 = 233,
            Assert00234 = 234,
            Assert00235 = 235,
            Assert00236 = 236,
            Assert00237 = 237,
            Assert00238 = 238,
            Assert00239 = 239,
            Assert00240 = 240,
            Assert00241 = 241,
            Assert00242 = 242,
            Assert00243 = 243,
            Assert00244 = 244,
            Assert00245 = 245,
            Assert00246 = 246,
            Assert00247 = 247,
            Assert00248 = 248,
            Assert00249 = 249,//free
            Assert00250 = 250,//free
            Assert00251 = 251,
            Assert00252 = 252,
            Assert00253 = 253,
            Assert00254 = 254,
            Assert00255 = 255,
            Assert00256 = 256,
            Assert00257 = 257,
            Assert00258 = 258,//free
            Assert00259 = 259,//free
            Assert00260 = 260,
            Assert00261 = 261,
            Assert00262 = 262,
            Assert00263 = 263,
            Assert00264 = 264,
            Assert00265 = 265,
            Assert00266 = 266,//free
            Assert00267 = 267,
            Assert00268 = 268,
            Assert00269 = 269,
            Assert00270 = 270,
            Assert00271 = 271,
            Assert00272 = 272,
            Assert00273 = 273,
            Assert00274 = 274,
            Assert00275 = 275,
            Assert00276 = 276,
            Assert00277 = 277,
            Assert00278 = 278,
            Assert00279 = 279,
            Assert00280 = 280,
            Assert00281 = 281,
            Assert00282 = 282,
            Assert00283 = 283,
            Assert00284 = 284,
            Assert00285 = 285,
            Assert00286 = 286,
            Assert00287 = 287,
            Assert00288 = 288,
            Assert00289 = 289,
            Assert00290 = 290,
            Assert00291 = 291,
            Assert00292 = 292,
            Assert00293 = 293,
            Assert00294 = 294,
            Assert00295 = 295,
            Assert00296 = 296,
            Assert00297 = 297,
            Assert00298 = 298,
            Assert00299 = 299,
            Assert00300 = 300,
            Assert00301 = 301,
            Assert00302 = 302,
            Assert00303 = 303,
            Assert00304 = 304,
            Assert00305 = 305,
            Assert00306 = 306,
            Assert00307 = 307,
            Assert00308 = 308,
            Assert00309 = 309,
            Assert00310 = 310,//free
            Assert00311 = 311,
            Assert00312 = 312,
            Assert00313 = 313,
            Assert00314 = 314,
            Assert00315 = 315,
            Assert00316 = 316,
            Assert00317 = 317,
            Assert00318 = 318,
            Assert00319 = 319,
            Assert00320 = 320,
            Assert00321 = 321,
            Assert00322 = 322,
            Assert00323 = 323,
            Assert00324 = 324,
            Assert00325 = 325
        }

        /// <summary>
        /// Кидает ассерт при НЕвыполнении заданного условия
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="source"></param>
        /// <returns>true - ассерта нет, false - ассерт есть</returns>
        public static bool FailIfNot(bool condition, Id id)
        {                        
            string assertText = Resources.BI_EXCEPTION_INTERNALBUG;            
#if DEBUG
            Debug.Assert(condition, assertText);
#endif
            if (!condition)
            {
                Trace.StartBlock("Assertion at " + id.ToString() + "!");
                Trace.Message(assertText);
                Trace.EndBlock();
            }
            return condition;
        }

        /// <summary>
        /// Кидает ассерт при выполнении заданного условия
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="source"></param>
        /// <returns>true - ассерта нет, false - ассерт есть</returns>
        public static bool FailIf(bool condition, Id id)
        {
            return FailIfNot(!condition, id);
        }

        /// <summary>
        /// Кидает ассерт безусловно
        /// </summary>        
        /// <param name="source"></param>
        /// <returns>всегда false</returns>
        public static bool Fail(Id id)
        {
            return FailIf(true, id);
        }        
    }
}
